<%@page import="org.quickbundle.orgauth.rmauthorizeresource.util.IRmAuthorizeResourceConstants"%>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@page import="com.dfhc.util.StringHelper"%>
<%@page import="com.dfhc.util.CryptoHelper"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />

<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/new/js/map.js"></script>
<title>添加 </title>

<%@ taglib uri="/dfhc" prefix="dfhc" %>
</head>
<body>
<article class="page-container">

<!-- 授权资源参照 -->
<dfhc:div templateId="h_ui_div_reference" id="referenceAuthorizeResource">
	<form name="searchFormReferenceAuthorizeResourceForm" id="searchFormReferenceAuthorizeResourceForm" action="">
	<!-- 保存外部调用传的参数 -->
	<!-- 单选/多选标志  0---单选 1--多选 -->
	<input type="hidden" name="selection" />
	<!-- 回填json表达式,[{"id":格式id1,"column":表格列号1},...,{"id":idn,"column":表格列号n }]-->
	<!-- id为html 控件id，表格序号从0开始 .如果是多选，回填的值用逗号分隔-->
	<input type="hidden" name="backFillExpression"/>
	<dfhc:div templateId="h_ui_div_search"> 
		<dfhc:button templateId="h_ui_search_button" id="" name="" onclick="javascript:_searchData($('#referenceAuthorizeResourceTable').DataTable());" />
	</dfhc:div>
	</form>
    	<dfhc:table templateId="table_h_ui" id="referenceAuthorizeResourceTable" >    	
		<dfhc:thead>
			<dfhc:tr> 
				<dfhc:th width="25">
<%-- 				   <dfhc:checkbox name="allId"    /> --%>
				</dfhc:th>	
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmAuthorizeResourceConstants.TABLE_COLUMN_CHINESE.get("name")%></dfhc:title>
				</dfhc:th>
			</dfhc:tr>
    	   </dfhc:thead>			
	</dfhc:table>           
</dfhc:div>
</article>


<script type="text/javascript">	
  $("#referenceAuthorizeResource").show();	
  $('#referenceAuthorizeResourceTable').dataTable({	
	     dom: 'Zlfrtip',	   		
		 ajax : function(data, callback, settings) {
		       var param =  splitParameter(data,$("#searchFormReferenceAuthorizeResourceForm").serializeObject()); 
                $.ajax({  
                        type: "POST",  
                        url: getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/rmauthorizeresource/ajaxExpressList")%>',  
                        cache : false,  //禁用缓存  
                        data:param,   
                        dataType: "json",  
                        success: function(result) {  
                                //异常判断与处理  
                                if (result.status=='0') {  
                                    alert(result.message);  
                                    return;  
                                }  
                                //封装返回数据  
                                var returnData = {};  
                                returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回  
                                returnData.recordsTotal = result.recordsTotal;//总记录数  
                                returnData.recordsFiltered = result.recordsTotal;//后台不实现过滤功能，每次查询均视作全部结果  
                                returnData.data = result.data;  
                                //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染  
                                //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕  
                                callback(returnData);  
                                //更新总记录数
                                $("#totalRecodSpan").html('共有数据：<strong>'+result.recordsTotal+'</strong> 条</span>');                                
                        },  
                        error: function(XMLHttpRequest, textStatus, errorThrown) {  
                            alert("查询失败");  
                        }  
                    });  
            },  
		"columns": [
		  {
		    "data":"id",
			"render":function(data,type,row,meta){
			   var content='<input type="checkbox" name="allId" class="allId" value="'+row.id+'"/>';
			   return content; 
			}
		  },
		  {"data":"name"}
		 
		],
		"columnDefs": [ {"searchable": false,
            "orderable": false,
            "targets": 0 }],
            bLengthChange: false,
	    "info":"",
	    "infoEmpty":""
	}); 	
var dataId;
// 关闭下拉框
function closeReferenceAuthorizeResourceContent(){
 $("#referenceAuthorizeResource").css({
    		left:0,
    		top:0,
    		display:"none",
    		width:0
    	   }).fadeOut("fast");
}

// 确认下拉框
//参数：
//selection： 单选/多选标志  0---单选 1--多选 
//backFillExpression 回填json表达式,[{"id":格式id1,"column":表格列号1},...,{"id":idn,"column":表格列号n }]-->
function confirmReferenceAuthorizeResourceContent(backFillExpression,selection){
	//判断用户是否选择
	var len = $('input[class="allId"]:checked').length;
	var count=0;
	var ids='';
	
	//回填表达式转成json对象
	//var jsonObj =  $.parseJSON(backFillExpression);
	var jsonObj =backFillExpression;

	//var tdValueMap =new Array();
	var tdValueMap = new Map();
	//获取td数量
	var trList = $("#referenceAuthorizeResourceTable tbody").children("tr");
	var tdNum ;
	if(trList.length>0){
		var tdList = trList.eq(0).children("td");
		tdNum = tdList.length;
	}else{
		alert('表格数据不完整!');
		return false;
	}
	 
	$("#referenceAuthorizeResourceTable input:checkbox").each(function(key,value){
            if($(value).prop('checked')){
              //循环取各列的值
              for(var i=0;i<tdNum;i++){
                 //根据列号获取对应对象id
                 var id = getIdByColumn(jsonObj,i);
                 if(id!=''){
                   var tdvalue;
                   if(i>0){
              	     tdvalue =$(this).parent().parent().children("td:eq("+i+")").text();
              	   }else{
              	     tdvalue = $(value).val();
              	   }
        		   if(!tdValueMap.containsKey(id)){
        		   	   tdValueMap.put(id,tdvalue);
        		   }else{
        		   	   tdValueMap.put(id,tdValueMap.get(id)+","+tdvalue);
        		   }      	   
              	  }
              }
              count += 1;  //游标加1
	      	  //dataId =$(value).val();
            }
        });
	
    	
      if(count==0){
       alert("请选择一条记录!");
       return false;	
      }
      if(count>1 && selection=='0'){
       alert("只能选择一条记录!");
       return false;	
      }

      if(count>0){
    	//回填控件属性
    	var keyList = tdValueMap.keys();
    	for(var i=0;i<keyList.length;i++){
    		$(window.parent.document).find("#"+keyList[i]).val(tdValueMap.get(keyList[i]));
    	}
    	//清空全选
    	$("#referenceAuthorizeResourceTable:checkbox").each(function(key,value){
            if($(value).prop('checked')){
            	$(this).prop("checked",false);
            }
        });
		 
		return true;  
    }
}	
</script>
</body>
</html>